python flask上传文件 | 您所在的位置:网站首页 › python flask debug › python flask上传文件 |
我有一个简单的烧瓶应用程序,我希望它能处理上传的excel文件,并在网页上显示它的数据。到目前为止,我有一个页面可以上传excel文件。在 在主.py在from flask import Flask, render_template, send_file, request from flask_uploads import UploadSet, configure_uploads, DOCUMENTS, IMAGES app = Flask(__name__) #the name 'datafiles' must match in app.config to DATAFILES docs = UploadSet('datafiles', DOCUMENTS) app.config['UPLOADED_DATAFILES_DEST'] = 'static/uploads' configure_uploads(app, docs) @app.route("/", methods=['GET']) def index(): # return send_file("templates/index.html") return render_template('index.html') @app.route("/upload", methods = ['GET', 'POST']) def upload(): #user_file is the name value in input element if requesthod == 'POST' and 'user_file' in request.files: filename = docs.save(request.files['user_file']) return filename return render_template('upload.html') @app.route("/mergedata", methods=['GET']) def merge_data(): return send_file("templates/mergeDataPage.html") if __name__ == "__main__": app.run(host='0.0.0.0', debug=True) 在上传.html在 ^{pr2}$ 一旦文件上传,我想用另一个python脚本来处理这个excel数据-这个脚本将获取excel文件,删除特殊字符并转换成csv文件/输出。我想在网页中显示csv输出。在 这个想法是让用户上传文件,按下一个按钮来清理数据,并将结果打印在输出框中。我该如何着手构建这样的场景?在 我对Flask还是个新手,但是到目前为止,学习这个很酷的web框架还是相当令人兴奋的。感谢您的帮助,谢谢!在 |
CopyRight 2018-2019 实验室设备网 版权所有 |